import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/widgets/bottom_sheet/filter_bottom_sheet.dart';
import 'package:finance_app/src/widgets/bottom_sheet/list_select_bottom_sheet.dart';

mixin FilterProductServiceSortMixin<T> on BaseProvider<T> {
  String currentSelectActive = 'Active';

  List<String> currentSelectFilterList = [];

  void onRequestRefresh();

  Future<void> onSelectActive() async {
    unFocus();
    Completer completer = Completer();
    obtainContext?.call((context) async {
      final result = await showProductStatusSelectBottomSheet(
          context, currentSelectActive);
      if (result != null) {
        currentSelectActive = result;
        onRequestRefresh();
        update();
        completer.complete(null);
      }
    });
    await completer.future;
  }

  void unFocus();

  List<String> get filterDataList;

  void onShowProductFilter() {
    unFocus();
    obtainContext.call((context) async {
      currentSelectFilterList = await showFilterProductBottomSheet(
        context,
        selectFilter: currentSelectFilterList,
        defaultFilter: filterDataList,
      );
      onRequestRefresh();
      update();
    });
  }

  void onShowServiceFilter() {
    unFocus();
    obtainContext.call((context) async {
      currentSelectFilterList = await showFilterServiceBottomSheet(
        context,
        selectFilter: currentSelectFilterList,
        defaultFilter: filterDataList,
      );
      onRequestRefresh();
      update();
    });
  }

  void onRemoveFilter(String value) {
    currentSelectFilterList.remove(value);
    onRequestRefresh();
    update();
  }
}
